//
//  EditShopNameViewController.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/11/25.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "EditShopNameViewController.h"

@interface EditShopNameViewController ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *phoneTF;
@property (nonatomic, strong) UIButton *editBtn;

@end

@implementation EditShopNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNaviWith:@"更换店铺名称"];
    [self setMainView];
}

- (void)setMainView
{
    UIView *headView = [UIView new];
    if (@available(iOS 11.0, *)) {
        headView.frame = CGRectMake(0, TopBarHeight_xs, SCREENWIDTH, 44);
    } else {
        // Fallback on earlier versions
        headView.frame = CGRectMake(0, TopBarHeight, SCREENWIDTH, 44);
    }
    headView.backgroundColor = UIColorFromHex(0xF0F0F0);
    [self.view addSubview:headView];
    
    UIImageView *leftIV = [UIImageView new];
    leftIV.frame = CGRectMake(15, 15, 14, 14);
    leftIV.image = [UIImage imageNamed:@"nowMobile"];
    [headView addSubview:leftIV];
    
    UILabel *mobileLab = [UILabel new];
    mobileLab.frame = CGRectMake(leftIV.right+15, 11,SCREENWIDTH-leftIV.right-30, 21);
    mobileLab.textColor = UIColorFromHex(0x9E9E9E);
    mobileLab.font = FontSemiboldSize(14);
    mobileLab.text = [NSString stringWithFormat:@"当前店铺名称：%@",self.shopName];
    [headView addSubview:mobileLab];
    
    UILabel *phoneLab = [UILabel new];
    phoneLab.frame = CGRectMake(15, headView.bottom+30, 200, 12);
    phoneLab.textColor = goldColor;
    phoneLab.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
    phoneLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:@"新店铺名称"];
    [self.view addSubview:phoneLab];
    
    self.phoneTF = [UITextField new];
    self.phoneTF.frame = CGRectMake(phoneLab.left, phoneLab.bottom+10, SCREENWIDTH-30, 16);
    self.phoneTF.delegate = self;
    //self.phoneTF.keyboardType = UIKeyboardTypeNumberPad;
    self.phoneTF.returnKeyType = UIReturnKeyNext;
    self.phoneTF.textColor = titleColor;
    UIButton *button = [self.phoneTF valueForKey:@"_clearButton"];
    [button setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
    self.phoneTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.phoneTF.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];
    self.phoneTF.placeholder = @"请输入店铺名称";
    [self.phoneTF setValue:UIColorFromHex(0xD8D8D8) forKeyPath:@"_placeholderLabel.textColor"];
    [self.phoneTF setValue:FontWithSize(16) forKeyPath:@"_placeholderLabel.font"];
    [self.view addSubview:self.phoneTF];
    
    UIView *lineView = [UIView new];
    lineView.frame = CGRectMake(phoneLab.left, _phoneTF.bottom+10, SCREENWIDTH-30, 1);
    lineView.backgroundColor = BacklineColor;
    [self.view addSubview:lineView];
    
    self.editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.editBtn.frame = CGRectMake(2*leftPadding, lineView.bottom+125, SCREENWIDTH-80, 50);
    self.editBtn.layer.cornerRadius = 25;
    self.editBtn.layer.masksToBounds = YES;
    self.editBtn.backgroundColor = goldColor;
    [self.editBtn setTitleColor:titleColor forState:UIControlStateNormal];
    self.editBtn.titleLabel.font = FontWithSize(18);
    //self.editBtn.backgroundColor = UIColorFromHex(0xD1D1D1);
    //[self.editBtn setTitleColor:UIColorFromHex(0x8D8D8D) forState:UIControlStateNormal];
    [self.editBtn setTitle:@"确认修改" forState:UIControlStateNormal];
    [self.editBtn addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.editBtn];
}

- (void)editClick:(UIButton *)btn
{
    if (self.phoneTF.text.length == 0) {
        [self ShowHUDWithMessage:@"店铺名称不能为空"];
        return;
    }
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:self.phoneTF.text forKey:@"name"];
    [dict setValue:[NSNumber numberWithInteger:self.id] forKey:@"sellerId"];
    [HttpRequest formPostPath:EditMyInfo_API params:dict resultBlock:^(id Data, MsgModel *msgModel) {
        [self ShowHUDWithMessage:@"修改成功"];
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

@end
